package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Employee;
import com.qf.bean.Role;
import com.qf.dao.EmployeeMapper;
import com.qf.dao.RoleMapper;
import com.qf.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.List;

/*
            敲得越多，钱越多！！！
            敲得越多，钱越多！！！
            敲得越多，钱越多！！！
*/
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> findbyids(int[] empid) {
        return employeeMapper.findbyids(empid);
    }

    //批量删除
    @Override
    public int deletes(int[] empids) {
        return employeeMapper.deletes(empids);
    }

    @Override
    public PageInfo<Employee> getall(int pageIndex,int pageSize,String username,String rolename,String deptname) {
        //1、指定分页参数
        PageHelper.startPage(pageIndex,pageSize);
        //2、调用dao层方法
        HashMap hashMap = new HashMap();
        hashMap.put("uname",username);
        hashMap.put("rname",rolename);
        hashMap.put("dname",deptname);
        List<Employee> findall = employeeMapper.findall(hashMap);
        //2、方钻给pageInfo
        PageInfo pageInfo = new PageInfo(findall);
        return pageInfo;
    }

    private RoleMapper roleMapper;
    @Override
    public Employee login(String username, String password) {
        Employee login = employeeMapper.login(username);
        if(login !=null){
            //用户名正确
            if(password.equals(login.getLoginpassword())){
                //查询当前用户所对应的角色信息
                Role role = roleMapper.selectByPrimaryKey(login.getRoleid());
                //2、根据角色信息查询角色所对应的菜单列表

                return login;
            }
            return null;
        }
        return null;
    }

    @Override
    public int deleteByPrimaryKey(Integer id,Integer id1) {
        HashMap hashMap = new HashMap();
        hashMap.put("uid",id);
        hashMap.put("state",id1);
        return employeeMapper.deleteByPrimaryKey(hashMap);
    }

    @Override
    @Transactional
    public int insert(Employee record) {
        return employeeMapper.insert(record);
    }

    @Override
    public int insertSelective(Employee record) {
        return 0;
    }

    @Override
    public Employee selectByPrimaryKey(Integer id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Employee record) {

        return employeeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Employee record) {
        return 0;
    }
}
